﻿using System;
using System.Text;

namespace com.nm.Security
{
    public class SHA1
    {
        public static string Compute(string inputText)
        {
            using (var sha1 = System.Security.Cryptography.SHA1.Create())
            {
                var b1 = sha1.ComputeHash(System.Text.Encoding.UTF8.GetBytes(inputText));
                var sBuilder = new StringBuilder();

                for (int i = 0; i < b1.Length; i++)
                {
                    sBuilder.Append(b1[i].ToString("x2"));
                }
                return sBuilder.ToString();
            }
        }
    }

    public class MD5
    {
        public static string Compute(string inputText)
        {
            using (var md5 = System.Security.Cryptography.MD5.Create())
            {
                var b1 = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(inputText));
                var sBuilder = new StringBuilder();

                for (int i = 0; i < b1.Length; i++)
                {
                    sBuilder.Append(b1[i].ToString("x2"));
                }
                return sBuilder.ToString();
            }
        }

        public static String GetPassWord(string str)
        {
            return MD5.Compute(str).ToUpper();
        }
    }
}